package com.example.cim;

import com.example.cim.init.RegistryZK;
import com.example.cim.init.ServerListListener;
import com.example.cim.util.IpUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.util.StringUtils;

import java.net.InetAddress;

@SpringBootApplication
public class SpringbootCimServerApplication implements CommandLineRunner {
	@Value("${server.host}")
	private String addr;
	@Value("${server.port}")
	private String httpPort ;
	@Value("${cim.websocket.port}")
	private String websocketPort ;
	@Value("${cim.app.port}")
	private String appPort ;

	public static void main(String[] args) {
		SpringApplication.run(SpringbootCimServerApplication.class, args);
	}

	@Override
	public void run(String... args) throws Exception {
		//获得本机IP
		if (StringUtils.isEmpty(addr)){
			 addr = IpUtil.getIp();
		}
		Thread thread = new Thread(new RegistryZK(addr,websocketPort,appPort,httpPort));
		thread.setName("registry-zk");
		thread.start() ;

		//监听服务
		Thread thread1 = new Thread(new ServerListListener());
		thread1.setName("zk-listener");
		thread1.start() ;
	}

}
